package com.ereport.dao;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.ereport.entity.ADP;
import com.ereport.util.ApplicationContext;

public class ADPDAO {

static Transaction tx;
	
	private  void endOperations(Session session) {
		
		session.close();
		session=null;
	}

	private  Session startOperations()throws Exception {
		
		Session session = ApplicationContext.getHiberSession().openSession();
		tx=session.beginTransaction();
		return session;
		
	}

	public int insert(ADP ac) throws Exception {
		Session session = startOperations();
		session.saveOrUpdate(ac);
		session.getTransaction().commit();
		endOperations(session);
		return 0;
		
	}

	public ADP getAdp(int id, String accName) throws Exception {
		Session session = startOperations();
		String qrystr="From ADP where exe_id=:id and accName=:accname";
		Query qr=session.createQuery(qrystr);
		qr.setInteger("id", id);
		qr.setString("accname", accName);
		ADP adp=(ADP) qr.uniqueResult();
		endOperations(session);
		return adp;
	}

}
